define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'platform_log/index' + location.search,
                    // add_url: 'platform_log/add',
                    // edit_url: 'platform_log/edit',
                    del_url: 'platform_log/del',
                    multi_url: 'platform_log/multi',
                    table: 'platform_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user_name', title: __('User_id'),operate: false},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'type', title: __('Type'), searchList:Config.typeList, formatter: Table.api.formatter.label},
                        {field: 'order_type', title: __('Order_type'), searchList:{1:'用户', 2:'商家'}, formatter: Table.api.formatter.label, operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', width:600, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                {
                    name:'detail',
                    text:'订单详情',
                    title:'订单详情',
                    icon:'fa fa-list',
                    classname:'btn btn-xs btn-primary btn-dialog',
                    visible: function (row) {
                        if(row.order_id) return true;
                        return false;
                    },
                    url: function (row){
                        if(row.type == 2){
                            return 'cash/detail?ids='+row.order_id;
                        }else if(row.type == 5){
                            return 'user_cash/detail?ids='+row.order_id;
                        }else if(row.type == 6 || row.type == 7){
                            return 'order_change/detail?ids='+row.order_id;
                        }else if(row.type == 8 || row.type == 9 || row.type == 13){
                            return 'order_continue/detail?ids='+row.order_id;
                        }else if(row.type == 10 || row.type == 11){
                            return 'order_continue/detail?ids='+row.order_id;
                        } else if(row.type == 14){
                            return 'order_refund/detail?ids='+row.order_id;
                        } else{
                            return 'order/detail?ids='+row.order_id;
                        }
                    }
                }
            ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});